<?php

namespace Application\model;

use Cola\Model;

class WhitelistModel extends Model
{
    public function getByAccount($account, $device, $returnBool = true)
    {
        $ip = ip();
        $sql = "select * from `ops_whitelist` where (`content` = '$account' and `type`=2) or (`content` = '$ip' and `type`=1) or (`content` = '$device' and `type`=3)";
        $res = $this->db->sql($sql);
        if ($res){
            if (!$returnBool) return $res;
            logfile('LoginModel', "account:$account or $ip  or $device is whitelist");
            return true;
        } else {
            return false;
        }

    }

    public function getInfo($account, $ip)
    {
        $data = [$account,$ip];
        $sql = "select * from `ops_whitelist` where `content` = ? or `content`=?";
        $res = $this->db->sql($sql,$data);
        if ($res){
            logfile('LoginModel', "account:$account is whitelist or ip:$ip is whitelist");
            return true;
        } else {
            return false;
        }
    }

    public function getPassDevice($code)
    {
        // 如果有status=1 则是不限制
        $sql = "select * from `gm_device` where `status`=1";
        $res = $this->db->sql($sql);
        if ($res){ return true;}

        $sql = "select * from `gm_device` where `code` = '$code' and `status`=0";
        $res = $this->db->sql($sql);
        if ($res){
            return true;
        } else {
            return false;
        }
    }

}